﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using University.Workshop.Model;

namespace University.Workshop.WinApp
{
    public partial class ModifyAppointment : Form
    {
        Patient patient = new Patient();
        Manager doctor = new Manager();
        Appointment appointment = new Appointment();

        public ModifyAppointment(Patient p, Manager d, Appointment a)
        {
            InitializeComponent();
            patient = p;
            doctor = d;
            appointment = a;
            LoadDataAppointment();
            //IssuePermits();
        }

        private void IssuePermits()
        {
            //buttonSaveChange.Enabled = RoleFacade.PermissionUser(Main.userMenu[3], "");
        }

        private void LoadDataAppointment()
        {
            textBoxFirstNameAgendaModify.Text = patient.FirstName;
            textBoxLastNameAgendaModify.Text = patient.LastName;
            textBoxPhoneAgendaModify.Text = Convert.ToString(patient.Phone);
            textBoxCiPatientAgendaModify.Text = patient.CIPatient;
            textBoxCellPhoneAgendaModify.Text = Convert.ToString(patient.CellPhone);
            textBoxPhoneAgendaModify.Text = Convert.ToString(patient.Phone);
            textBoxEmailAgendaModify.Text = patient.Email;
            textBoxDoctorNameAgendaModify.Text = doctor.FirstName;
            textBoxCiDoctorAgendaModify.Text = doctor.CIManager;
            comboBoxState.Text = appointment.StateAppointment;
            comboBoxTimeAgendaModify.Text = appointment.TimeAppointment;
            //textBoxStateAgendaModify.Text = agenda.es
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonSaveChange_Click(object sender, EventArgs e)
        {
            //Agenda agenda = new Agenda();
            Appointment appointment = new Appointment();
            appointment.DateAppointment = Convert.ToString(monthCalendarAppointment.SelectionEnd.ToShortDateString());            
            appointment.TimeAppointment = comboBoxTimeAgendaModify.Text;
            string idAppointment = textBoxCiPatientAgendaModify.Text;            
            appointment.StateAppointment = comboBoxState.Text;
            if (AgendaManager.ModifyAppointment(appointment, idAppointment))
            {
                MessageBox.Show("Successful registration");
            }
            else
            {
                MessageBox.Show("The new Appointment could not be registered");
            }
        }
    }
}
